Given a matrix of type `scipy.sparse.coo_matrix` how to determine index and value of maximum of each row?

Getrow(i) returns a 1 x n CSR matrix, which has an indices attribute that gives the row indices of the corresponding values in the data attribute. (We know the shape is 1 x n, so we don't have to deal with the indptr attribute. ) So this will work.

Up vote 0 down vote favorite share g+ share fb share tw.

Given a sparse matrixR of type scipy.sparse. Coo_matrix of shape 1.000.000 x 70.000 I figured out that row_maximum = max(R. Getrow(i).

Data) will give me the maximum value of the i-th row. What I need now is the index corresponding to the value row_maximum. Any ideas how to achieve that?

Thanks for any advice in advance! Python matrix scipy maximum sparse link|improve this question asked Feb 13 at 22:01Aufwind1,860316 85% accept rate.

Getrow(i) returns a 1 x n CSR matrix, which has an indices attribute that gives the row indices of the corresponding values in the data attribute. (We know the shape is 1 x n, so we don't have to deal with the indptr attribute. ) So this will work: row = R.

Getrow(i) max_index = row.indicesrow.data.argmax() if row. Nnz else 0 We have to deal with the case where row. Nnz is 0 separately, because row.data.argmax() will raise an exception if row.

Data is an empty array.

Use numpy. Argmax (or scipy. Argmax which is the same thing) index_of_maximum = scipy.

Argmax(R. Getrow(i). Data).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions